package com.mohan.dlxj.service.impl;

import com.mohan.dlxj.common.JsonResult;
import com.mohan.dlxj.mapper.FlawMapper;
import com.mohan.dlxj.pojo.Circuit;
import com.mohan.dlxj.pojo.Flaw;
import com.mohan.dlxj.pojo.FlawType;
import com.mohan.dlxj.service.FlawService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FlawServiceImpl implements FlawService {
  @Autowired
  private FlawMapper flawMapper;

  @Override
  public JsonResult getCircuitList(Integer page, Integer limit) {
    JsonResult jsonResult = new JsonResult();
    jsonResult.setCode(0);
    jsonResult.setMsg("获取数据成功");

    page = limit * (page - 1);
    List<FlawType> list = flawMapper.selectAllTyle(page, limit);
    jsonResult.setCount(flawMapper.selectAllType());//总条数
    jsonResult.setData(list);
    return jsonResult;
  }

  @Override
  public void saveType(FlawType flawType) {
    flawMapper.saveType(flawType);
  }

  @Override
  public void updateType(FlawType flawType) {
    flawMapper.updateType(flawType);
  }

  @Override
  public JsonResult getFlawList(Integer page, Integer limit) {
    JsonResult jsonResult = new JsonResult();
    jsonResult.setCode(0);
    jsonResult.setMsg("获取数据成功");

    page = limit * (page - 1);
    List<Flaw> list = flawMapper.selectAllFlaw(page, limit);
    jsonResult.setCount(flawMapper.selectAllFlawNumber());//总条数
    jsonResult.setData(list);
    return jsonResult;
  }

  @Override
  public void updateFlaw(long id) {
    flawMapper.updateFlaw(id);
  }

  @Override
  public JsonResult getSomeFlawList(long page, long limit, Flaw flaw) {
    JsonResult jsonResult = new JsonResult();
    jsonResult.setCode(0);
    jsonResult.setMsg("获取数据成功");

    page = limit * (page - 1);
    List<Flaw> list = flawMapper.selectSomeFlaw(page, limit,flaw);
    jsonResult.setCount(flawMapper.selectSomeFlawNum());//总条数
    jsonResult.setData(list);
    return jsonResult;
  }

  @Override
  public void ensureLevel(long id, long level) {
    flawMapper.updateLevel(id,level);
  }
}
